package com.lcl.jarvis.admin.modules.business.service.impl;

import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import com.lcl.jarvis.common.model.PageResult;
import com.lcl.jarvis.admin.modules.business.dto.request.TbDoctorsReqDTO;
import com.lcl.jarvis.admin.modules.business.dto.response.TbDoctorsRespDTO;
import com.lcl.jarvis.admin.modules.business.dto.request.TbDoctorsPageReqDTO;

import com.lcl.jarvis.admin.modules.business.mapper.TbDoctorsMapper;
import com.lcl.jarvis.admin.modules.business.entity.TbDoctors;
import com.lcl.jarvis.admin.modules.business.service.ITbDoctorsService;
import lombok.RequiredArgsConstructor;

/**
 * 医生Service业务层处理
 * 
 * @author licl
 * @date 2024-06-21 09:44:48
 */
@Service
@RequiredArgsConstructor
public class TbDoctorsServiceImpl extends ServiceImpl<TbDoctorsMapper, TbDoctors> implements ITbDoctorsService {

    /**
     * 新增医生
     *
     * @param body 医生
     * @return 结果
     */
    @Override
    public Integer add(TbDoctorsReqDTO body) {
        TbDoctors entity = BeanUtil.copyProperties(body, TbDoctors.class);
        return baseMapper.insert(entity);
    }

    /**
     * 批量删除医生
     *
     * @param ids 需要删除的医生主键
     * @return 结果
     */
    @Override
    public Integer remove(List<Long> ids) {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 修改医生
     * 
     * @param body 医生
     * @return 结果
     */
    @Override
    public Integer update(TbDoctorsReqDTO body) {
        TbDoctors entity = BeanUtil.copyProperties(body, TbDoctors.class);

        return baseMapper.updateById(entity);
    }


    /**
     * 查询医生
     *
     * @param id 医生主键
     * @return 医生
     */
    @Override
    public TbDoctorsRespDTO detail(Long id) {
        TbDoctors entity = baseMapper.selectById(id);
        return BeanUtil.copyProperties(entity, TbDoctorsRespDTO.class);
    }

    /**
     * 查询医生列表
     *
     * @param req
     * @return 医生
     */
    @Override
    public PageResult<TbDoctorsRespDTO> page(TbDoctorsPageReqDTO req) {
        LambdaQueryWrapper<TbDoctors> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.like(StrUtil.isNotBlank(req.getName()), TbDoctors::getName, req.getName());
        queryWrapper.eq(StrUtil.isNotBlank(req.getSpecialty()), TbDoctors::getSpecialty, req.getSpecialty());
        queryWrapper.eq(StrUtil.isNotBlank(req.getEmail()), TbDoctors::getEmail, req.getEmail());
        queryWrapper.eq(StrUtil.isNotBlank(req.getPhone()), TbDoctors::getPhone, req.getPhone());
        queryWrapper.eq(StrUtil.isNotBlank(req.getDepartment()), TbDoctors::getDepartment, req.getDepartment());
        queryWrapper.eq(StrUtil.isNotBlank(req.getMedical()), TbDoctors::getMedical, req.getMedical());
        Page<TbDoctors> page = baseMapper.selectPage(req.buildPage(), queryWrapper);
        return PageResult.of(page, TbDoctorsRespDTO.class);
    }

}
